#include <iostream>

using namespace std;
bool P(int num)
{
    if (num <= 1)
        return false;
    for (int i = 2; i * i <= num; ++i)
    {
        if (num % i == 0)
            return false;
    }
    return true;
}

int f(int num)
{
    int s = num - 1;
    int l = num + 1;

    while (true)
        {
        if (P(s))
        {
            return s;
        } else if (P(l))
        {
            return l;
        }
        s--;
        l++;
        }
}

int main()
{
    string s;
    cout<<"Введите слова на английском"<<endl;
    getline(cin, s);
    int n = s.find(' ');
    string s1 = s.substr(0, n);
    int s11=0;
    int s21=0;
    int s31 = 0;
    s.erase(0, n+1);
    n = s.find(' ');
    string s2 = s.substr(0, n);
    s.erase(0, n+1);
    string s3 = s;
    string b;
    if((s1=="one") or (s1=="two") or (s1=="three") or (s1=="four") or (s1=="five") or (s1=="six") or (s1=="seven") or (s1=="eight") or (s1=="nine") or (s1=="zero"))
    {
        if (s1=="one")
            s11+=1;
        if (s1=="two")
            s11+=2;
        if (s1=="three")
            s11+=3;
        if (s1=="four")
            s11+=4;
        if (s1=="five")
            s11+=5;
        if (s1=="six")
            s11+=6;
        if (s1=="seven")
            s11+=7;
        if (s1=="eight")
            s11+=8;
        if (s1=="nine")
            s11+=9;
        if (s1=="zero")
            s11+=0;
    }
    else
    {
        b = "Wrong input";
    }
    if (b=="Wrong input")
    {
        cout<<"Wrong input";
        exit(0);
    }

    if((s2=="one") or (s2=="two") or (s2=="three") or (s2=="four") or (s2=="five") or (s2=="six") or (s2=="seven") or (s2=="eight") or (s2=="nine") or (s2=="zero"))
    {
        if (s2=="one")
            s21+=1;
        if (s2=="two")
            s21+=2;
        if (s2=="three")
            s21+=3;
        if (s2=="four")
            s21+=4;
        if (s2=="five")
            s21+=5;
        if (s2=="six")
            s21+=6;
        if (s2=="seven")
            s21+=7;
        if (s2=="eight")
            s21+=8;
        if (s2=="nine")
            s21+=9;
        if (s2=="zero")
            s21+=0;
    }
    else
    {
        b = "Wrong input";
    }
    if (b=="Wrong input")
    {
        cout<<"Wrong input";
        exit(0);
    }
    if((s3=="one") or (s3=="two") or (s3=="three") or (s3=="four") or (s3=="five") or (s3=="six") or (s3=="seven") or (s3=="eight") or (s3=="nine") or (s3=="zero"))
    {
        if (s3=="one")
            s31+=1;
        if (s3=="two")
            s31+=2;
        if (s3=="three")
            s31+=3;
        if (s3=="four")
            s31+=4;
        if (s3=="five")
            s31+=5;
        if (s3=="six")
            s31+=6;
        if (s3=="seven")
            s31+=7;
        if (s3=="eight")
            s31+=8;
        if (s3=="nine")
            s31+=9;
        if (s3=="zero")
            s31+=0;
    }
    else
    {
        b = "Wrong input";
    }
    if (b=="Wrong input")
    {
        cout<<"Wrong input";
        exit(0);
    }
    cout<<s11<<s21<<s31<<endl;

    int q = s11*100 + s21*10 + s31;
    int z = f(q);
    cout<<z;


    return 0;
}
